﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using PeekService;

namespace PeekWebApp.handler
{
    /// <summary>
    /// GetRecommendList 的摘要说明
    /// </summary>
    public class IndexHandler: IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "application/json";
            string action = context.Request["action"];
            switch (action)
            { 
                case "Recommend"://推荐景点
                    int count = 0;
                    List<RecommendModel> list = new ExtendService().GetRecomendList("","",true,0,0,out count);
                    context.Response.Write(CommonService.ConvertToJSON(list));
                    break;
                case "Links":
                    List<string> listLinks = new ExtendService().GetLinks();
                    context.Response.Write(CommonService.ConvertToJSON(listLinks));
                    break;
                case "Intrest":
                    List<ContentInterest> listIntrest = new ContentInterestService().GetAll();
                    context.Response.Write(CommonService.ConvertToJSON(listIntrest));
                    break;             
                case "IntrestDetail":
                    string id = context.Request["id"];
                    if (!string.IsNullOrEmpty(id))
                    {
                        id = CommonService.PreventJsInjection(CommonService.HTMLEncode(id));
                        if (!string.IsNullOrEmpty(id))
                        {
                            ContentInterest model = new ContentInterestService().GetModel(id);
                            if (model != null)
                            {
                                context.Response.Write(CommonService.ConvertToJSON(model));
                            }
                            else
                            {
                                context.Response.Write(CommonService.ConvertToJSON("0"));
                            }
                        }
                        else
                        {
                            context.Response.Write(CommonService.ConvertToJSON("0"));
                        }
                    }
                    else
                    {
                        context.Response.Write(CommonService.ConvertToJSON("0"));
                    }
                    break;
                case "Adv"://广告信息
                    context.Response.Write(CommonService.ConvertToJSON(new AdvertisementService().GetCurrentAdvertisement()));
                    break;
                case "Region":
                    context.Response.Write(CommonService.ConvertToJSON(new ExtendService().GetCountryRegion()));
                    break;
            }          
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}